package com.jingsheng.jingshengcity.mvp.ui.activity;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerSearchComponent;
import com.jingsheng.jingshengcity.di.module.SearchModule;
import com.jingsheng.jingshengcity.mvp.contract.SearchContract;
import com.jingsheng.jingshengcity.mvp.presenter.SearchPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.SearchActivityHistoryAdapter;
import com.jingsheng.jingshengcity.widgets.decoration.GridItemDecoration;
import com.jingsheng.jingshengcity.widgets.flowlayout.TagAdapter;
import com.jingsheng.jingshengcity.widgets.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/10.
 */

public class SearchActivity extends BaseActivity<SearchPresenter> implements SearchContract.View {

    @NonNull
    @BindView(R.id.flow_layout)
    TagFlowLayout mTagFlowLayout;
    @NonNull
    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;

    private LayoutInflater mInflater;
    private String[] mVals = new String[]{"衣服", "衣服", "衣服", "衣服", "衣服", "衣服", "衣服"};
    private List<String> mList = new ArrayList<>();

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerSearchComponent
                .builder()
                .appComponent(appComponent)
                .searchModule(new SearchModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        return R.layout.activity_search;
    }

    @Override
    public void initData() {
        mInflater = LayoutInflater.from(this);
        mTagFlowLayout.setAdapter(new TagAdapter<String>(mVals) {
            @Override
            protected View getView(ViewGroup parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.layout_search_tv,
                        parent, false);
                tv.setText(s);
                return tv;
            }

            @Override
            protected void onSelect(ViewGroup parent, View view, int position) {
                //view.setBackgroundResource(R.drawable.checked_bg);
            }

            @Override
            protected void onUnSelect(ViewGroup parent, View view, int position) {
                //view.setBackgroundResource(R.drawable.normal_bg);
            }

            @Override
            protected boolean select(int position) {

                return super.select(position);
            }

        });

        mList.add("1");
        mList.add("1");

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        SearchActivityHistoryAdapter mConfirmOrderActivityAdapter = new SearchActivityHistoryAdapter(R.layout.adapter_search_history_item, mList);
        mConfirmOrderActivityAdapter.openLoadAnimation();
        mRecyclerView.addItemDecoration(new GridItemDecoration(this, R.drawable.list_gray_devider));
        mRecyclerView.setAdapter(mConfirmOrderActivityAdapter);
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public boolean useFragment() {
        return false;
    }


}